<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
    <meta charset="UTF-8">
    <title>垂直居中的方法</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>

        .box {
            width: 400px;
            height: 300px;
            background-color: red;
            margin: 50vh auto 0;
            transform: translate(0, -50%);
        }
    </style>
</head>
<body>
<div class="box"></div>
</body>
</html>